package com.ruoyi.teacher.controller;

import java.util.List;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.teacher.domain.VO.TeacherVo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teacher.domain.teacher;
import com.ruoyi.teacher.service.IteacherService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 教师信息Controller
 * 
 * @author chenxl
 * @date 2025-04-08
 */
@RestController
@RequestMapping("/teacher/teacher")
public class teacherController extends BaseController
{
    @Autowired
    private IteacherService teacherService;

    /**
     * 查询教师信息列表
     */
//    @PreAuthorize("@ss.hasPermi('teacher:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(teacher teacher)
    {
        startPage();
        List<teacher> list = teacherService.selectteacherList(teacher);
        return getDataTable(list);
    }

    /**
     * 导出教师信息列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:teacher:export')")
    @Log(title = "教师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, teacher teacher)
    {
        List<teacher> list = teacherService.selectteacherList(teacher);
        ExcelUtil<teacher> util = new ExcelUtil<teacher>(teacher.class);
        util.exportExcel(response, list, "教师信息数据");
    }

    /**
     * 获取教师信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('teacher:teacher:query')")
    @GetMapping(value = "/{uuid}")
    public AjaxResult getInfo(@PathVariable("uuid") String uuid)
    {
        return success(teacherService.selectteacherByUuid(uuid));
    }

    /**
     * 新增教师信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:teacher:add')")
    @Log(title = "教师信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody teacher teacher)
    {
        teacher.setUuid(IdUtils.fastSimpleUUID());
        return toAjax(teacherService.insertteacher(teacher));
    }

    /**
     * 修改教师信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:teacher:edit')")
    @Log(title = "教师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody teacher teacher)
    {
        return toAjax(teacherService.updateteacher(teacher));
    }

    /**
     * 删除教师信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:teacher:remove')")
    @Log(title = "教师信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uuids}")
    public AjaxResult remove(@PathVariable String[] uuids)
    {
        return toAjax(teacherService.deleteteacherByUuids(uuids));
    }

    /**
     *导入课程信息
     */
    @PostMapping("/importteacherData")
    @ResponseBody
    public AjaxResult importteacherListData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<teacher> util = new ExcelUtil<teacher>(teacher.class);
        List<teacher> teacherList = util.importExcel(file.getInputStream());
        String message = teacherService.importteacherListroom(teacherList, updateSupport);
        return AjaxResult.success(message);
    }
    @GetMapping("/getAllTeacher")
    public TableDataInfo getAllTeacher(TeacherVo teacherVo)
    {
        startPage();
        List<TeacherVo> list = teacherService.selectAllteacherList(teacherVo);
        return getDataTable(list);
    }
}
